//
//  XQCourseFirstTableViewCell.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/11/29.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class CourseFistCollectViewCell: UICollectionViewCell {
    var icon = UIImageView()
    var label = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        InitUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func InitUI(){
        self.contentView.layer.borderWidth = 0.3
        self.contentView.layer.borderColor = UIColor.lightGray.cgColor
        
        icon = UIImageView.init(frame: CGRect.zero)
        self.contentView .addSubview(icon)
        
        label = UILabel.init(frame: CGRect.zero)
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = UIColor.lightGray
        label.textAlignment = .center
        self.contentView .addSubview(label)
    
        icon.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView.snp.left).offset(10)
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.width.equalTo(20)
            make.height.equalTo(20)
        }
        
        label.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.left.equalTo(icon.snp.right).offset(3)
        }
        
        
    }
    
}


class XQCourseFirstTableViewCell: UITableViewCell,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
    public var homeself = XQHomeViewController()
    var collectionView: UICollectionView!
    
    private  let CourseFistCollectViewCellID = "CourseFistCollectViewCellID"

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        InitUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func InitUI() {
        
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.itemSize = CGSize.init(width: SCREEN_WIDTH/3, height: 40)
        
        self.collectionView = UICollectionView.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: 40), collectionViewLayout: layout)
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.showsVerticalScrollIndicator = false
        self.collectionView.showsHorizontalScrollIndicator = false
        self.collectionView.bounces = false
        self.collectionView.backgroundColor = UIColor.white
        self.contentView .addSubview( self.collectionView)
        
        self.collectionView.register(CourseFistCollectViewCell.self, forCellWithReuseIdentifier: CourseFistCollectViewCellID)
        
    }
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 3
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseFistCollectViewCellID, for: indexPath) as!CourseFistCollectViewCell
        switch indexPath.row {
        case 0:
            cell.icon.image = UIImage.init(named: "shipin")
            cell.label.text = "视频课程"
            break
        case 1:
            cell.icon.image = UIImage.init(named: "xianxia")
            cell.label.text = "线下培训"
            break
        case 2:
            cell.icon.image = UIImage.init(named: "zhibo")
            cell.label.text = "直播课程"
            break
        default:
            break
        }
        return cell
    }
    

}
